  *analysis with weights

  *regression	 prep
     global mod =  "i.sex  i.religion  i.residence i.occupation i.education i.language i.friends i.team_support i.children  i.country##i.legal_status  [pweight=weight]"
* clustered ses
     global ses =  "cl(caseid)"

*programme for restrictions
   est clear
   ssc install lincomest
   capture program drop restrictamce
   program def restrictamce
*Romania can only be paired with regular status  
   lincomest ( _b[3.country] *0) + ( _b[3.country] +  _b[3o.country#2o.legal_status]) *1
   est store Romania
   
   est restore reg
*other countries we average over all levels of legal status
   foreach x of numlist 2 4 5 {
   lincomest  (`x'.country *1/2)  + (`x'.country + `x'.country#2.legal_status) * 1/2
	est store country`x'
	est restore reg
	}
   
*effect legal status (irregular cannot go with Romania)
lincomest ( _b[2.legal_status] *1/4) + ( _b[2.legal_status] +  _b[2.country#2.legal_status]) *1/4 + ///
                               ( _b[2.legal_status] +  _b[3o.country#2o.legal_status]) *0+ ///
							   ( _b[2.legal_status] + _b[4.country#2.legal_status]) *1/4 + ///
							   ( _b[2.legal_status] +  _b[5.country#2.legal_status]) *1/4  
							  est store legal
							  						
 end
 
 *reg
     eststo: reg outcome $mod , baselevels $ses coeflegend	 
     estimate store reg
	 estimate restore reg
	 restrictamce


